<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class AlertMe - RDoc Documentation</title>

<link href="./fonts.css" rel="stylesheet">
<link href="./rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
</script>

<script src="./js/jquery.js"></script>
<script src="./js/navigation.js"></script>
<script src="./js/search_index.js"></script>
<script src="./js/search.js"></script>
<script src="./js/searcher.js"></script>
<script src="./js/darkfish.js"></script>


<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="./index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link">Object
  
</div>

    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-new">::new</a>
    
    <li ><a href="#method-i-getDeviceByType">#getDeviceByType</a>
    
    <li ><a href="#method-i-getDevices">#getDevices</a>
    
    <li ><a href="#method-i-getHeatingControllerById">#getHeatingControllerById</a>
    
    <li ><a href="#method-i-getHouseholdDetails">#getHouseholdDetails</a>
    
    <li ><a href="#method-i-login">#login</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-AlertMe">
  <h1 id="class-AlertMe" class="class">
    class AlertMe
  </h1>

  <section class="description">
    
  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(username, password, caller, bg = false)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          <br />set <strong>bg</strong> to true for Brittish Gas

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/alertme.rb, line 12</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span>, <span class="ruby-identifier">caller</span>, <span class="ruby-identifier">bg</span> = <span class="ruby-keyword">false</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">bg</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">true</span>
    <span class="ruby-ivar">@uri</span> = <span class="ruby-constant">URI</span>(<span class="ruby-string">&quot;https://api.bgchlivehome.co.uk/v5&quot;</span>)
  <span class="ruby-keyword">else</span> 
    <span class="ruby-ivar">@uri</span> = <span class="ruby-constant">URI</span>(<span class="ruby-string">&quot;https://api.alertme.com/v5&quot;</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@session</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">login</span>(<span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span>, <span class="ruby-identifier">caller</span>)
  <span class="ruby-ivar">@username</span> = <span class="ruby-identifier">username</span>
  <span class="ruby-ivar">@password</span> = <span class="ruby-identifier">password</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-getDeviceByType" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">getDeviceByType</span><span
            class="method-args">(type)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          Get all devices of a certain type<br />
          HAHVACThermostat, HAHVACThermostatSLR2, HeatingController, HAHVACTemperatureSensor, Lamp, all
          
          
          

          
          <div class="method-source-code" id="getDeviceByType-source">
            <pre><span class="ruby-comment"># File lib/alertme.rb, line 53</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">getDeviceByType</span>(<span class="ruby-identifier">type</span>)
  <span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">host</span>, <span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">port</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = <span class="ruby-keyword">true</span>

  <span class="ruby-identifier">header</span> = {<span class="ruby-string">&#39;Cookie&#39;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@cookie</span>}

  <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices/#{type}&quot;</span>, <span class="ruby-identifier">header</span>)
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
  <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-getDevices" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">getDevices</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          Return all devices associated to your account
          
          
          

          
          <div class="method-source-code" id="getDevices-source">
            <pre><span class="ruby-comment"># File lib/alertme.rb, line 42</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">getDevices</span>
  <span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">host</span>, <span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">port</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = <span class="ruby-keyword">true</span>

  <span class="ruby-identifier">header</span> = {<span class="ruby-string">&#39;Cookie&#39;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@cookie</span>}

  <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices&quot;</span>, <span class="ruby-identifier">header</span>)
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
  <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-getHeatingControllerById" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">getHeatingControllerById</span><span
            class="method-args">(id)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          Get a Heating Controller by Identifier
          
          
          

          
          <div class="method-source-code" id="getHeatingControllerById-source">
            <pre><span class="ruby-comment"># File lib/alertme.rb, line 64</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">getHeatingControllerById</span>(<span class="ruby-identifier">id</span>)
  <span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">host</span>, <span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">port</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = <span class="ruby-keyword">true</span>

  <span class="ruby-identifier">header</span> = {<span class="ruby-string">&#39;Cookie&#39;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@cookie</span>}

  <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices/HeatingController/#{id}&quot;</span>, <span class="ruby-identifier">header</span>)
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
  <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-getHouseholdDetails" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">getHouseholdDetails</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          Return Building Details of your household / property
          
          
          

          
          <div class="method-source-code" id="getHouseholdDetails-source">
            <pre><span class="ruby-comment"># File lib/alertme.rb, line 75</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">getHouseholdDetails</span>
  <span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">host</span>, <span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">port</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = <span class="ruby-keyword">true</span>

  <span class="ruby-identifier">header</span> = {<span class="ruby-string">&#39;Cookie&#39;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@cookie</span>}

  <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@uri.path}/users/#{@username}/householdDetails&quot;</span>, <span class="ruby-identifier">header</span>)
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
  <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>)[<span class="ruby-string">&quot;values&quot;</span>]
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-login" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">login</span><span
            class="method-args">(username, password, caller)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          login to your AlertMe / Hive Active Heating account. (required if your session times out. initially called when class is initialized)
          
          
          

          
          <div class="method-source-code" id="login-source">
            <pre><span class="ruby-comment"># File lib/alertme.rb, line 23</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">login</span>(<span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span>, <span class="ruby-identifier">caller</span>)
  <span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">host</span>, <span class="ruby-ivar">@uri</span>.<span class="ruby-identifier">port</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = <span class="ruby-keyword">true</span>

  <span class="ruby-identifier">request</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Post</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@uri.path}/login&quot;</span>)
  <span class="ruby-identifier">request</span>.<span class="ruby-identifier">set_form_data</span>({<span class="ruby-string">&quot;username&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">username</span>, <span class="ruby-string">&quot;password&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">password</span>, <span class="ruby-string">&quot;caller&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">caller</span>})

  <span class="ruby-identifier">response</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">request</span>)
  <span class="ruby-identifier">all_cookies</span> = <span class="ruby-identifier">response</span>.<span class="ruby-identifier">get_fields</span>(<span class="ruby-string">&#39;set-cookie&#39;</span>)
  <span class="ruby-identifier">cookies_array</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-identifier">all_cookies</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">cookie</span> <span class="ruby-operator">|</span>
      <span class="ruby-identifier">cookies_array</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">cookie</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&#39;; &#39;</span>)[<span class="ruby-value">0</span>])
  }
  <span class="ruby-ivar">@cookie</span> = <span class="ruby-identifier">cookies_array</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&#39;; &#39;</span>)

  <span class="ruby-identifier">json</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>)
  <span class="ruby-ivar">@hub</span> = <span class="ruby-identifier">json</span>[<span class="ruby-string">&quot;hubIds&quot;</span>].<span class="ruby-identifier">first</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.0.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>

